<template>
	<view class="container">
		<view class="order-detail">
			<view v-if="userAddrDto" class="delivery-addr">
				<view class="user-info">
					<text class="item">
						{{ userAddrDto.receiver }}
					</text>
					<text class="item">
						{{ userAddrDto.mobile }}
					</text>
				</view>
				<view class="addr">
					{{ userAddrDto.province }}{{ userAddrDto.city }}{{ userAddrDto.area }}{{
            userAddrDto.area
          }}{{ userAddrDto.addr }}
				</view>
			</view>

			<!-- 商品信息 -->
			<view v-if="orderItemDtos" class="prod-item">
				<block v-for="(item, index) in orderItemDtos" :key="index">
					<view class="item-cont" :data-prodid="item.prodId" @tap="toProdPage">
						<view class="prod-pic">
							<image :src="item.pic" />
						</view>
						<view class="prod-info">
							<view class="prodname">
								{{ item.prodName }}
							</view>
							<view class="prod-info-cont">
								<text class="number">
									数量：{{ item.prodCount }}
								</text>
								<text class="info-item">
									{{ item.skuName }}
								</text>
							</view>
							<view class="price-nums clearfix">
								<text class="prodprice">
									<text class="symbol">
										￥
									</text>
									<text class="big-num">
										{{ wxs.parsePrice(item.price)[0] }}
									</text>
									<text class="small-num">
										.{{ wxs.parsePrice(item.price)[1] }}
									</text>
								</text>
								<view class="btn-box" />
							</view>
						</view>
					</view>
				</block>
			</view>

			<!-- 订单信息 -->
			<view class="order-msg">
				<view class="msg-item">
					<view class="item">
						<text class="item-tit">
							订单编号：
						</text>
						<text class="item-txt">
							{{ orderNumber }}
						</text>
					</view>
					<view class="item">
						<text class="item-tit">
							下单时间：
						</text>
						<text class="item-txt">
							{{ createTime }}
						</text>
					</view>
				</view>
				<view class="msg-item">
					<view class="item">
						<text class="item-tit">
							支付方式：
						</text>
						<text class="item-txt">
							微信支付
						</text>
					</view>
					<view class="item">
						<text class="item-tit">
							配送方式：
						</text>
						<text class="item-txt">
							普通配送
						</text>
					</view>
					<view class="item">
						<text v-if="!!remarks" class="item-tit">
							订单备注：
						</text>
						<text class="item-txt remarks">
							{{ remarks }}
						</text>
					</view>
				</view>
			</view>

			<view class="order-msg">
				<view class="msg-item">
					<view class="item">
						<view class="item-tit">
							订单总额：
						</view>
						<view class="item-txt price">
							<text class="symbol">
								￥
							</text>
							<text class="big-num">
								{{ wxs.parsePrice(total)[0] }}
							</text>
							<text class="small-num">
								.{{ wxs.parsePrice(total)[1] }}
							</text>
						</view>
					</view>
					<view class="item">
						<view class="item-tit">
							运费：
						</view>
						<view class="item-txt price">
							<text class="symbol">
								￥
							</text>
							<text class="big-num">
								{{ wxs.parsePrice(transfee)[0] }}
							</text>
							<text class="small-num">
								.{{ wxs.parsePrice(transfee)[1] }}
							</text>
						</view>
					</view>
					<view class="item">
						<view class="item-tit">
							优惠券：
						</view>
						<view class="item-txt price">
							<text class="symbol">
								-￥
							</text>
							<text class="big-num">
								{{ wxs.parsePrice(reduceAmount)[0] }}
							</text>
							<text class="small-num">
								.{{ wxs.parsePrice(reduceAmount)[1] }}
							</text>
						</view>
					</view>
					<view class="item payment">
						<view class="item-txt price">
							实付款：
							<text class="symbol">
								￥
							</text>
							<text class="big-num">
								{{ wxs.parsePrice(actualTotal)[0] }}
							</text>
							<text class="small-num">
								.{{ wxs.parsePrice(actualTotal)[1] }}
							</text>
						</view>
					</view>
				</view>
			</view>

			<!-- 底部栏 -->
			<view v-if="status==5||status==6" class="order-detail-footer">
				<text v-if="status==5||status==6" class="dele-order" @tap="delOrderList">
					删除订单
				</text>
			</view>
		</view>
	</view>
</template>

<script>
	import number from "../../wxs/number";
	import {
		mineOrderList
	} from "../../api/mine.js"
	export default {
		data() {
			return {
				wxs: number(),
				remarks: '',
				orderItemDtos: [],
				reduceAmount: '',
				transfee: '',
				status: 0,
				actualTotal: 0,
				userAddrDto: null,
				orderNumber: '',
				createTime: '',
				total: 0, // 商品总额

			}
		},
		methods: {
			/**
			 * 生命周期函数--监听页面加载
			 */
			onLoad(options) {
				this.loadOrderDetail(options.orderNumber)
			},
			/**
			 * 跳转商品详情页
			 * @param e
			 */
			toProdPage(e) {
				const prodid = e.currentTarget.dataset.prodid
				uni.navigateTo({
					url: '/pages/prod/prod?prodid=' + prodid
				})
			},
			/**
			 * 加载订单数据
			 */
			loadOrderDetail(orderNum) {
				uni.showLoading() // 加载订单详情
				mineOrderList(orderNum)
					.then(({
						data
					}) => {
						this.orderNumber = orderNum
						this.actualTotal = data.actualTotal
						this.userAddrDto = data.userAddrDto
						this.remarks = data.remarks
						this.orderItemDtos = data.orderItems
						this.createTime = data.createTime
						this.status = data.status
						this.transfee = data.transfee
						this.reduceAmount = data.reduceAmount
						this.total = data.total
						uni.hideLoading()
					})
			},

			/**
			 * 删除已完成||已取消的订单
			 */
			delOrderList() {
				let orderNumber = this.orderNumber
				uni.showModal({
					title: '',
					content: '确定要删除此订单吗？',
					confirmColor: '#eb2444',
					success(res) {
						if (res.confirm) {
							uni.showLoading()
							deleteOrder(orderNumber)
								.then(() => {
									uni.hideLoading()
									uni.showToast({
										title: res || '删除成功',
										icon: 'none'
									})
									setTimeout(() => {
										uni.redirectTo({
											url: '/pages/orderList/orderList'
										})
									}, 1000)
								})
						}
					}
				})
			},

		}
	}
</script>

<style scoped lang="scss">
	.container {
		background: #f4f4f4;
	}

	.order-detail {
		margin-bottom: 120rpx;
		padding-bottom: 160rpx;

		.delivery-addr {
			padding: 20rpx 30rpx;
			background: #fff;

			.user-info {
				line-height: 48rpx;
				word-wrap: break-word;
				word-break: break-all;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 1;
				-webkit-box-orient: vertical;

				.item {
					font-size: 28rpx;
					margin-right: 30rpx;
					vertical-align: top;
					display: inline-block;
				}
			}

			.addr {
				font-size: 26rpx;
				line-height: 36rpx;
				color: #999;
				word-wrap: break-word;
			}
		}
	}

	.prod-item {
		background-color: #fff;
		margin-top: 15rpx;
		font-size: 28rpx;

		.item-cont {
			.prod-pic {
				image {
					width: 180rpx;
					height: 180rpx;
					width: 100%;
					height: 100%;
				}

				font-size: 0;
				display: block;
				width: 160rpx;
				height: 160rpx;
				overflow: hidden;
				background: #fff;
				margin-right: 16rpx;
			}

			display: flex;
			align-items: center;
			padding: 30rpx;
			border-top: 2rpx solid #f1f1f1;

			.prod-info {
				margin-left: 10rpx;
				font-size: 28rpx;
				width: 100%;
				position: relative;
				height: 80px;
				-webkit-flex: 1;
				-ms-flex: 1;
				-webkit-box-flex: 1;
				-moz-box-flex: 1;
				flex: 1;

				.prodname {
					font-size: 28rpx;
					line-height: 40rpx;
					max-height: 86rpx;
					overflow: hidden;
					display: -webkit-box;
					-webkit-line-clamp: 1;
					-webkit-box-orient: vertical;
					text-overflow: ellipsis;
					word-break: break-all;
				}

				.prod-info-cont {
					position: relative;
					color: #999;
					margin-top: 10rpx;
					font-size: 24rpx;

					.info-item {
						color: #999;
						height: 28rpx;
						margin-top: 10rpx;
						font-size: 24rpx;
						overflow: hidden;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
						text-overflow: ellipsis;
						word-break: break-all;
						width: 70%;
					}

					.number {
						float: left;
						margin-right: 20rpx;
					}
				}
			}
		}

		.price-nums {
			margin-top: 30rpx;

			.prodprice {
				color: #333;
				height: 50rpx;
				line-height: 50rpx;
				font-size: 24rpx;
				float: left;
			}

			.btn-box {
				float: right;
				text-align: right;

				.btn {
					padding: 6rpx 30rpx;
					line-height: 36rpx;
					margin-left: 20rpx;
					font-size: 24rpx;
					display: inline-block;
					border: 2rpx solid #e4e4e4;
					border-radius: 50rpx;
				}
			}
		}
	}

	.order-msg {
		background: #fff;
		margin-top: 15rpx;
		font-size: 28rpx;

		.msg-item {
			padding: 20rpx;
			border-top: 2rpx solid #f1f1f1;

			&:first-child {
				border: 0;
			}

			.item {
				display: flex;
				padding: 10rpx 0;
				align-items: center;
				box-sizing: border-box;

				.item-tit {
					min-width: 140rpx;
					color: #999;
					line-height: 48rpx;
				}

				.item-txt {
					flex: 1;
					line-height: 48rpx;
				}

				.item-txt.remarks {
					max-width: 600rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.copy-btn {
					display: block;
					margin-left: 20rpx;
					border: 2rpx solid #e4e4e4;
					padding: 6rpx 24rpx;
					border-radius: 50rpx;
					font-size: 24rpx;
					line-height: 28rpx;
				}

				.item-txt.price {
					text-align: right;
				}
			}

			.item.payment {
				border-top: 2rpx solid #f1f1f1;
				color: #eb2444;
				padding-top: 30rpx;
			}
		}
	}

	.order-detail-footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		max-width: 750rpx;
		background: #fff;
		margin: auto;
		display: -webkit-flex;
		display: -webkit-box;
		display: -moz-box;
		display: -ms-flexbox;
		display: flex;
		padding: 22rpx 0;
		font-size: 26rpx;
		box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);

		.dele-order {
			margin-left: 20rpx;
			line-height: 60rpx;
			display: block;
			margin-right: 20rpx;
			width: 150rpx;
			text-align: center;
		}

		.footer-box {
			flex: 1;
			text-align: right;
			line-height: 60rpx;

			.buy-again {
				font-size: 26rpx;
				color: #fff;
				background: #eb2444;
				border-radius: 50rpx;
				padding: 10rpx 20rpx;
				margin-right: 20rpx;
			}

			.apply-service {
				font-size: 26rpx;
				border-radius: 50rpx;
				padding: 10rpx 20rpx;
				border: 1px solid #e4e4e4;
				margin-right: 20rpx;
			}
		}
	}

	.clearfix {
		&:after {
			content: " ";
			display: table;
			clear: both;
		}
	}

	.order-state {
		height: 70rpx;
		line-height: 70rpx;
		text-align: right;
		margin-right: 20rpx;

		.order-sts {
			color: #eb2444;
			font-size: 28rpx;
		}

		.order-sts.gray {
			color: #999;
			height: 32rpx;
			line-height: 32rpx;
		}

		.order-sts.normal {
			color: #333;
		}
	}
</style>